function isPhone() {
    var model = UIATarget.localTarget().model();
    
    return model == "iPhone" || model == "iPhone Simulator";
}

function isPad() {
    var model = UIATarget.localTarget().model();
    
    return model == "iPad" || model == "iPad Simulator";
}
var start;
var stop;

function testDuration() {
    if (start) {
        stop = start;
        start = new Date();
        
        var duration = (start.getTime() - stop.getTime()) / 1000;
        if (duration > 5) {
            UIALogger.logFail("Duration is too high: " + duration + " sec");
        } else if (duration > 2) {
            UIALogger.logIssue("Duration might be too high: " + duration + " sec");
        } else {
            UIALogger.logMessage("Duration is OK: " + duration + " sec");
        }
    } else {
        start = new Date();
    }
}

function tap(element) {
    try {
        testDuration();
        element.tap();
    } catch(error) {
        UIALogger.logFail("Can't tap element: " + element);
    }
}

function tapRightNavigationBarButton() {
    try {
        tap(UIATarget.localTarget().frontMostApp().navigationBar().rightButton());
    } catch(error) {
        UIALogger.logFail("Can't tap rigth button on navigation bar." + error);
    }
}

function tapLeftNavigationBarButton() {
    try {
        tap(UIATarget.localTarget().frontMostApp().navigationBar().leftButton());
    } catch(error) {
        UIALogger.logFail("Can't tap left button on navigation bar.");
    }
}

function setValueToTextField(name, value) {
    try {
        UIATarget.localTarget().frontMostApp().mainWindow().textFields()[name].setValue(value);
    } catch(error) {
        UIALogger.logFail("Can't set value " + value + " to text field " + name + ".");
    }
}

function setValueToSecureTextFields(name, value) {
    try {
        UIATarget.localTarget().frontMostApp().mainWindow().secureTextFields()[name].setValue(value);
    } catch(error) {
        UIALogger.logFail("Can't set value " + value + " to secure text field " + name + ".");
    }
}